import 'dart:async';

import 'package:iea/provider/base/base_resp.dart';
import 'package:iea/models/paidCauserDetail_models/detail_picBar_model.dart';
import 'package:iea/provider/resource/paidCauserDetail_api_provider.dart';

class DetailPicBarBloc {
  final _apiClient = PaidCauserDetailApiProvider();

  StreamSubscription<BaseResp> _detailPicBarscription;
  final StreamController<BaseResp> _detailPicBarController =
      StreamController<BaseResp>.broadcast();
  Stream<BaseResp> get detailPicBarStream => _detailPicBarController.stream;

  /*
  *  获取公开课类型列表
  * @links
  */
  void detailPicBar([params]) {
    _detailPicBarscription?.cancel();
    _detailPicBarscription = _apiClient
        .getGoodsDetail(params)
        .asStream()
        .listen((BaseResp data) {
      if (data.result) {
        data.data = DetailPicBarModel.fromJson(data.data);
      }
      _detailPicBarController.add(data);
    });
  }

  void dispose() {
    _detailPicBarscription?.cancel();
    _detailPicBarController.close();
  }
}